﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyClassLibrary;
using MyDB;

namespace MyProgram
{
    public partial class FrmExamOverviewCT : FrmBase
    {
        public FrmExamOverviewCT()
        {
            InitializeComponent();
        }

        MedicareDataClassesDataContext db = new MedicareDataClassesDataContext();

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text == "")
            {
                var q = from f in db.ExamOverview
                        join c in db.ExamCategories on f.檢驗類別ID equals c.檢驗類別ID
                        select new { f.檢驗項目ID, f.項目_英文名稱_, f.中文名稱, f.性別, f.單位, f.檢驗正常值_上限_, f.檢驗正常值_下限_, f.危險百分比, c.檢驗類別名稱 };

                this.dataGridView1.DataSource = q.ToList();
            }
            else
            {
                var q = from f in db.ExamOverview
                        join c in db.ExamCategories on f.檢驗類別ID equals c.檢驗類別ID
                        where f.中文名稱.Contains(this.textBox1.Text)
                        select new { f.檢驗項目ID, f.項目_英文名稱_, f.中文名稱, f.性別, f.單位, f.檢驗正常值_上限_, f.檢驗正常值_下限_, f.危險百分比, c.檢驗類別名稱 };

                this.dataGridView1.DataSource = q.ToList();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FrmExamOverAdd fd = new FrmExamOverAdd();
            fd.ShowDialog();

            MedicareDataClassesDataContext dba = new MedicareDataClassesDataContext();

            var q = from f in dba.ExamOverview
                    join c in dba.ExamCategories on f.檢驗類別ID equals c.檢驗類別ID
                    select new { f.檢驗項目ID, f.項目_英文名稱_, f.中文名稱, f.性別, f.單位, f.檢驗正常值_上限_, f.檢驗正常值_下限_, f.危險百分比, c.檢驗類別名稱 };

            this.dataGridView1.DataSource = q.ToList();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FrmExamOverMF fd = new FrmExamOverMF();

            if (this.dataGridView1.DataSource != null)
            {
                fd.drugovIndx = int.Parse(this.dataGridView1.SelectedCells[0].Value.ToString());

                fd.ShowDialog();

                MedicareDataClassesDataContext dba = new MedicareDataClassesDataContext();

                var q = from f in dba.ExamOverview
                        join c in dba.ExamCategories on f.檢驗類別ID equals c.檢驗類別ID
                        select new { f.檢驗項目ID, f.項目_英文名稱_, f.中文名稱, f.性別, f.單位, f.檢驗正常值_上限_, f.檢驗正常值_下限_, f.危險百分比, c.檢驗類別名稱 };

                this.dataGridView1.DataSource = q.ToList();
            }
        }
    }
}
